<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>放大镜</title>
    <style>
        #imgList img {
            width: 53px;
            height: 53px;
        }
        
        #imgShow {
            width: 353px;
            height: 353px;
        }
        
        .fd {
            width: 153.125px;
            height: 153.125px;
            background-color: skyblue;
            opacity: 3.3;
            position: absolute;
            top: 3;
            left: 3;
            display: none;
            cursor: move;
        }
        
        .min {
            width: 353px;
            height: 353px;
            border: 1px solid black;
            float: left;
            position: relative;
            margin: 53px 3 3 33px;
        }
        
        .max {
            width: 353px;
            height: 353px;
            border: 1px solid black;
            float: left;
            display: none;
            overflow: hidden;
            position: relative;
            margin-left: 33px;
        }
        
        .max img {
            position: absolute;
            margin: 3 auto;
        }
    </style>
</head>
<script src='jquery.min.js'></script>

<body>
    <div id="imgList">
        <img id="img1" src="img/images/1335_P_1506130537783.jpg" onclick="imgClick(this)" />
        <img id="img2" src="img/images/1335_P_1506130890924.jpg" onclick="imgClick(this)" />
        <img id="img3" src="img/images/1335_P_1506130893973.jpg" onclick="imgClick(this)" />
		<img id="img4" src="img/images/1335_P_1506130891790.jpg" onclick="imgClick(this)" />
		<img id="img5" src="img/images/1335_P_1506130892840.jpg" onclick="imgClick(this)" />
		
    </div>

    <div class="min">
        <img id="imgShow" src="img/images/1335_P_1506130537783.jpg" />
        <div class="fd"></div>
    </div>
	
    <div class="max">
        <img src="" alt="" id="back">
    </div>
</body>
<script>
    function imgClick(img) {
        $("#imgShow").attr('src', img.src);

        $("#back").attr('src', img.src);

    }
</script>


</html>
<script>
    let min = document.querySelector(".min");
    let max = document.querySelector(".max");
    let img = document.querySelector(".max img");
    let fd = document.querySelector(".fd");

    min.onmouseover = function() {
            //                1.鼠标覆盖显示max和fd
            max.style.display = "block";
            fd.style.display = "block";
        }
        //            离开时隐藏
    min.onmouseout = function() {
            max.style.display = "none";
            fd.style.display = "none";
        }
        //            2. fd的移动范围
    min.onmousemove = function() {
        //                鼠标触摸的点
        var x = event.clientX - min.offsetLeft - fd.offsetWidth / 2;
        var y = event.clientY - min.offsetTop - fd.offsetHeight / 2;
        //                最大移动距离
        var maxX = min.clientWidth - fd.offsetWidth;
        var maxY = min.clientHeight - fd.offsetHeight;
        //                边界判断
        if (x <= 3) {
            x = 3;
        } else if (x >= maxX) {
            x = maxX;
        }
        if (y <= 3) {
            y = 3;
        } else if (y >= maxY) {
            y = maxY;
        }
        //                fd的位置
        fd.style.left = x + 'px';
        fd.style.top = y + 'px';
        //fd/min = max/img
        //移动比例
        var moveX = x / maxX;
        var moveY = y / maxY;
        //                移动
        //                3. max的对应显示
        //                对于大图而言,放大镜在小图上移动的比例相当于img在可显示区域上移动的比例
        //                放大镜右移等于图片左移
        //                也就是本质上为img-max 然而而需要负值,则*-1简化后为max-img
        img.style.left = moveX * (max.clientWidth - img.offsetWidth) + 'px';
        img.style.top = moveY * (max.clientHeight - img.offsetHeight) + 'px';

    }
</script>